/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.translog.gui.fornecedor;

import br.com.translog.controlador.ControladorFornecedor;
import br.com.translog.controlador.ControladorFuncionario;
import br.com.translog.gui.outro.FrmMenuPrincipal;
import br.com.translog.modelo.Fornecedor;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;

/**
 *
 * @author ThiFerreira
 */
public class FrmFornecedorExcluir extends javax.swing.JFrame {

    /**
     * Creates new form FrmFornecedorExcluir
     */
    public FrmFornecedorExcluir() {
        initComponents();
        setLocationRelativeTo(null);
    }
    
    Fornecedor fornecedor = new Fornecedor();

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlFuncionarioExcluir = new javax.swing.JPanel();
        lblExcluiFuncionario = new javax.swing.JLabel();
        lblMatricula = new javax.swing.JLabel();
        lblNome = new javax.swing.JLabel();
        lblCargo = new javax.swing.JLabel();
        lblEmailEmpresarial = new javax.swing.JLabel();
        txtMatricula = new javax.swing.JTextField();
        txtNome = new javax.swing.JTextField();
        txtCargo = new javax.swing.JTextField();
        txtEmailEmpresarial = new javax.swing.JTextField();
        btnPesquisar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        lblEmailEmpresarial1 = new javax.swing.JLabel();
        txtCargo1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pnlFuncionarioExcluir.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlFuncionarioExcluir.setMaximumSize(new java.awt.Dimension(936, 384));
        pnlFuncionarioExcluir.setMinimumSize(new java.awt.Dimension(936, 384));

        lblExcluiFuncionario.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblExcluiFuncionario.setText("EXCLUIR FORNECEDOR");
        lblExcluiFuncionario.setName(""); // NOI18N

        lblMatricula.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblMatricula.setText("Matrícula");

        lblNome.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblNome.setText("Razão social ");

        lblCargo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCargo.setText("Nome Fantasia");

        lblEmailEmpresarial.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEmailEmpresarial.setText("Email Empresarial");

        txtNome.setEditable(false);

        txtCargo.setEditable(false);

        txtEmailEmpresarial.setEditable(false);

        btnPesquisar.setText("Pesquisar");
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        lblEmailEmpresarial1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEmailEmpresarial1.setText("Site");

        txtCargo1.setEditable(false);

        javax.swing.GroupLayout pnlFuncionarioExcluirLayout = new javax.swing.GroupLayout(pnlFuncionarioExcluir);
        pnlFuncionarioExcluir.setLayout(pnlFuncionarioExcluirLayout);
        pnlFuncionarioExcluirLayout.setHorizontalGroup(
            pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                                .addComponent(lblEmailEmpresarial)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                                        .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtEmailEmpresarial, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)))
                            .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblMatricula)
                                    .addComponent(lblNome)
                                    .addComponent(lblCargo)
                                    .addComponent(lblEmailEmpresarial1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtNome, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
                                    .addComponent(txtCargo)
                                    .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                                        .addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnPesquisar))
                                    .addComponent(txtCargo1)))))
                    .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(lblExcluiFuncionario)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlFuncionarioExcluirLayout.setVerticalGroup(
            pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFuncionarioExcluirLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblExcluiFuncionario)
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMatricula)
                    .addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisar))
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNome)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCargo)
                    .addComponent(txtCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmailEmpresarial1)
                    .addComponent(txtCargo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmailEmpresarial)
                    .addComponent(txtEmailEmpresarial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(56, 56, 56)
                .addGroup(pnlFuncionarioExcluirLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExcluir)
                    .addComponent(btnCancelar))
                .addContainerGap(76, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlFuncionarioExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 506, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlFuncionarioExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed

        try {

            //Verifica se o campo de pesquisa nao esta em "branco"...
            if (!txtMatricula.getText().equals("")) {
                fornecedor = ControladorFornecedor.getInstFornecedor().consultaFornecedor(Integer.parseInt(txtMatricula.getText()));
                if (fornecedor == null) {
                    JOptionPane.showMessageDialog(null, "Fornecedor não Encontrado!");
                } else {
                    //Convertendo as datas para exibicao no JTextField...
                    //String dataAdmBanco = new SimpleDateFormat("dd/MM/yyyy").format(funcionario.getDataAdmissao());

                    //Setando os valores do objeto funcionario nos JTextFields...
                    txtCargo1.setText(fornecedor.getCodigoPessoaJuridica().getSite());
                    txtEmailEmpresarial.setText(fornecedor.getCodigoPessoaJuridica().getEmail());
                    txtEmailEmpresarial.setText(fornecedor.getCodigoPessoaJuridica().getEmail());
                    txtNome.setText(fornecedor.getCodigoPessoaJuridica().getRazaoSocial());
                    txtCargo.setText(fornecedor.getCodigoPessoaJuridica().getNomeFantasia());

                }

            } else {
                JOptionPane.showMessageDialog(null, "Dados Obrigatórios não Informados!");
            }

        } catch (Exception e) {
        }

    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed

        try {
            ControladorFornecedor.getInstFornecedor().excluiFornecedor(fornecedor, fornecedor.getCodigoPessoaJuridica(), fornecedor.getCodigoLogradouro(), fornecedor.getCodigoPessoaJuridica().getCliente());
        } catch (Exception e) {
        }

    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        
        new FrmMenuPrincipal().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmFornecedorExcluir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmFornecedorExcluir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmFornecedorExcluir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmFornecedorExcluir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmFornecedorExcluir().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JLabel lblCargo;
    private javax.swing.JLabel lblEmailEmpresarial;
    private javax.swing.JLabel lblEmailEmpresarial1;
    private javax.swing.JLabel lblExcluiFuncionario;
    private javax.swing.JLabel lblMatricula;
    private javax.swing.JLabel lblNome;
    private javax.swing.JPanel pnlFuncionarioExcluir;
    private javax.swing.JTextField txtCargo;
    private javax.swing.JTextField txtCargo1;
    private javax.swing.JTextField txtEmailEmpresarial;
    private javax.swing.JTextField txtMatricula;
    private javax.swing.JTextField txtNome;
    // End of variables declaration//GEN-END:variables
}
